//
//  DHBrandProductCollectionCell.m
//  Dresshere
//
//  Created by ZhangPeng on 2018/6/11.
//  Copyright © 2018年 张朋. All rights reserved.
//

#import "DHBrandProductCollectionCell.h"

@implementation DHBrandProductCollectionCell

- (void)awakeFromNib {
    [super awakeFromNib];

    self.stateLabel.layer.cornerRadius = self.stateLabel.height / 2;
    self.stateLabel.clipsToBounds = YES;
    self.stateLabel.layer.borderWidth = 2;
    self.stateLabel.layer.borderColor = [[UIColor whiteColor] CGColor];
//    NSDictionary *attribtDic = @{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]};
//     NSMutableAttributedString *attribtStr = [[NSMutableAttributedString alloc]initWithString:oldStr attributes:attribtDic];
//    self.rightPriceLabel.attributedText = attribtStr;
}

- (void)uploadCell:(NSDictionary *)model{
    if ([[model objectForKey:@"snapshots"] count] > 0) {
        [self.coverImgView dh_setImageURLString:[[model objectForKey:@"snapshots"] objectAtIndex:0]];
    }else{
        [self.coverImgView setImage:[UIImage imageNamed:@"img_default.jpg"]];
    }
    self.nameLabel.text = [model objectForKey:@"name"];
    self.typeLabel.text = [[model objectForKey:@"brand"] objectForKey:@"name"];
    
    self.leftPriceLabel.text = [NSString stringWithFormat:@" ￥%@",[model objectForKey:@"sales_price"]];
    // 中划线
    NSDictionary *attribtDic = @{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]};
    NSMutableAttributedString *attribtStr = [[NSMutableAttributedString alloc]initWithString:self.leftPriceLabel.text attributes:attribtDic];
    self.leftPriceLabel.attributedText = attribtStr;
    
    self.leftPriceLabel.adjustsFontSizeToFitWidth = YES;
    self.rightPriceLabel.adjustsFontSizeToFitWidth = YES;
    
    CGFloat sales_price= [[model objectForKey:@"sales_price"] floatValue];
    CGFloat discount_price = [[model objectForKey:@"discount_price"] floatValue];
    if (sales_price == discount_price) {
        self.leftPriceLabel.hidden = YES;
        self.rightPriceLabel.textAlignment = NSTextAlignmentCenter;
        if ([[model objectForKey:@"can_be_purchased"] boolValue] && ![[model objectForKey:@"can_be_leased"] boolValue]) {
            self.stateLabel.text = @"售";
            self.stateLabel.backgroundColor = [UIColor colorWithHexString:@"#5F657B"];
            self.rightPriceLabel.text = [NSString stringWithFormat:@"￥%@",[model objectForKey:@"discount_price"]];
        }else{
            self.stateLabel.text = @"租";
            self.stateLabel.backgroundColor = [UIColor colorWithHexString:@"#F7BB18"];
            self.rightPriceLabel.text = [NSString stringWithFormat:@"￥%@",[model objectForKey:@"lease_price"]];
        }
    }else{
        self.rightPriceLabel.textAlignment = NSTextAlignmentRight;
        if ([[model objectForKey:@"can_be_purchased"] boolValue] && ![[model objectForKey:@"can_be_leased"] boolValue]) {
            self.stateLabel.text = @"售";
            self.stateLabel.backgroundColor = [UIColor colorWithHexString:@"#5F657B"];
            self.rightPriceLabel.text = [NSString stringWithFormat:@"￥%@ /",[model objectForKey:@"discount_price"]];
        }else{
            self.stateLabel.text = @"租";
            self.stateLabel.backgroundColor = [UIColor colorWithHexString:@"#F7BB18"];
            self.rightPriceLabel.text = [NSString stringWithFormat:@"￥%@ /",[model objectForKey:@"lease_price"]];
        }
    }
}

@end
